#!/bin/bash -e

function info() {
echo Usage: `basename $0` [-e err_rate -m min_len] reads1.fq[.gz] reads2.fq[.gz]
exit 2
}


while getopts  ":e:m:p:" opts
do
        case  $opts  in
		e) err_rate=$OPTARG;;
        m) min_len=$OPTARG;;
		p) out_prefix=$OPTARG;;
		*) info;;
        esac
done
shift $(($OPTIND - 1))

if [ -z "$2" ]; then info; fi
if [ -z "$min_len" ]; then min_len=20; fi
if [ -z "$err_rate" ]; then err_rate=0.1; fi

. $var

quality=20
overlap=1
cut_repeat=2
# overlap=1 # prefer to discard
# err_rate=0.2 # prefer to discard

# truseq_0_20=AGATCGGAAGAGCACACGTC
# truseq_uni_res_com_20=AGATCGGAAGAGCGTCGTGT
a1=GAGACAGGTTGGA
a2=TTTAAAACTGCCA
a3=TCCAACCTGTCTC
a4=TGGCAGTTTTAAA

${tools_path}/Python-2.7.10/python \
    $cutadapt \
    -q $quality \
    --overlap $overlap \
    -e $err_rate \
    -n $cut_repeat \
    -m $min_len \
    -a AGATCGGAAGAGC \
    -A AGATCGGAAGAGC \
    -o $out_prefix.1.cut_g.fastq \
    -p $out_prefix.2.cut_g.fastq \
    $1 $2 

${tools_path}/Python-2.7.10/python \
$cutadapt \
-q $quality \
--overlap $overlap \
-e $err_rate \
-n $cut_repeat \
-m $min_len \
-u +33 \
-U +33 \
-a $a1 \
-A $a1 \
-a $a2 \
-A $a2 \
-a $a3 \
-A $a3 \
-a $a4 \
-A $a4 \
-o $out_prefix.1.cut.fastq \
-p $out_prefix.2.cut.fastq \
$out_prefix.1.cut_g.fastq $out_prefix.2.cut_g.fastq

. $cmd_done
